#pragma once

#include "ProfileApplication.h"

#include "Package.h"
#include "Profile.h"

namespace uml {

const bool ProfileApplication::isStrict_default_ = false;
void ProfileApplication::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    DirectedRelationship::fromJson(json, errorList);
    appliedProfile_ = JsonSerializable::create<Profile>(json.value("appliedProfile"), errorList);

    applyingPackage_ = JsonSerializable::create<Package>(json.value("applyingPackage"), errorList);

    isStrict_ = json.value("isStrict").toBool(isStrict_default_);
}

void ProfileApplication::toJson(QJsonObject& json) {
    DirectedRelationship::toJson(json);
    if (appliedProfile_) {
        QJsonObject appliedProfile_json;
        appliedProfile_->toJson(appliedProfile_json);
        json.insert("appliedProfile", appliedProfile_json);
    }
    if (applyingPackage_) {
        QJsonObject applyingPackage_json;
        applyingPackage_->toJson(applyingPackage_json);
        json.insert("applyingPackage", applyingPackage_json);
    }
    if (isStrict_ != isStrict_default_) {
        json.insert("isStrict", isStrict_);
    }
}

/// <summary>
/// appliedProfile getter
/// References the Profiles that are applied to a Package through this
/// ProfileApplication.
/// </summary>
shared_ptr<Profile> ProfileApplication::appliedProfile() const {
    return appliedProfile_;
}

/// <summary>
/// appliedProfile setter
/// References the Profiles that are applied to a Package through this
/// ProfileApplication.
/// </summary>
void ProfileApplication::setAppliedProfile(shared_ptr<Profile> value) {
    appliedProfile_ = value;
}

/// <summary>
/// applyingPackage getter
/// The package that owns the profile application.
/// </summary>
shared_ptr<Package> ProfileApplication::applyingPackage() const {
    return applyingPackage_;
}

/// <summary>
/// applyingPackage setter
/// The package that owns the profile application.
/// </summary>
void ProfileApplication::setApplyingPackage(shared_ptr<Package> value) {
    applyingPackage_ = value;
}

/// <summary>
/// isStrict getter
/// Specifies that the Profile filtering rules for the metaclasses of the referenced
/// metamodel shall be strictly applied.
/// </summary>
bool ProfileApplication::isStrict() const {
    return isStrict_;
}

/// <summary>
/// isStrict setter
/// Specifies that the Profile filtering rules for the metaclasses of the referenced
/// metamodel shall be strictly applied.
/// </summary>
void ProfileApplication::setIsStrict(bool value) {
    isStrict_ = value;
}

} // namespace uml
